package chapter3.lc80;

//LC 80  删除有序数组中的重复项 II  没个元素最多出现两次

/**
 * 双指针，如果nums[i] == nums[j-1]就跳过
 */
public class RemoveDuplicatesSorted2 {
    public int removeDuplicates(int[] nums) {
        int j = 0;
        for (int i = 0; i < nums.length; i++) {
            if (j < 2) {
                nums[j++] = nums[i];
            }else if(nums[j - 2] != nums[i]){
                nums[j++] = nums[i];
            }
        }
        return j;
    }
}
